Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,34 @@
|
|
| 1 |
-
import
|
| 2 |
-
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
res = qa(question=question, context=context)
|
| 34 |
-
return {"answer": res.get("answer", ""), "score": round(float(res.get("score", 0.0)), 3)}
|
| 35 |
-
|
| 36 |
-
# --- Gradio UI (with AxionX brand style) ---
|
| 37 |
-
with gr.Blocks(title="AxionX Digital β AI QA Demo") as demo:
|
| 38 |
-
gr.Markdown(
|
| 39 |
-
"""
|
| 40 |
-
# π€ **AxionX Digital β Question Answering Demo**
|
| 41 |
-
Type a paragraph in **Context**, then ask a **Question** about it.
|
| 42 |
-
*(Model: distilbert-base-cased-distilled-squad β lightweight for stability)*
|
| 43 |
-
---
|
| 44 |
-
"""
|
| 45 |
-
)
|
| 46 |
-
with gr.Row():
|
| 47 |
-
ctx = gr.Textbox(label="Context", lines=8, value=EXAMPLE_CONTEXT)
|
| 48 |
-
q = gr.Textbox(label="Question", value=EXAMPLE_QUESTION)
|
| 49 |
-
btn = gr.Button("π Get Answer")
|
| 50 |
-
out = gr.JSON(label="Result (answer, score)")
|
| 51 |
-
btn.click(predict, inputs=[ctx, q], outputs=[out])
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
-
|
|
|
|
| 1 |
+
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
def main():
|
| 5 |
+
st.set_page_config(page_title="Gradio QA Demo", page_icon="π€", layout="wide")
|
| 6 |
+
st.title("π€ AxionX Digital β Question Answering Demo")
|
| 7 |
+
|
| 8 |
+
st.markdown("Type a paragraph in **Context**, then ask a **Question** about it.")
|
| 9 |
+
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def load_model():
|
| 12 |
+
return pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 13 |
+
|
| 14 |
+
qa = load_model()
|
| 15 |
+
|
| 16 |
+
context = st.text_area("Context", value=(
|
| 17 |
+
"AxionX Digital builds model-training tools for AI developers. "
|
| 18 |
+
"We fine-tune open-source LLMs for customer support, finance, and legal use cases. "
|
| 19 |
+
"We also provide evaluation dashboards and fast private deployments."
|
| 20 |
+
), height=200)
|
| 21 |
+
|
| 22 |
+
question = st.text_input("Question", value="What does AxionX Digital build?")
|
| 23 |
+
|
| 24 |
+
if st.button("π Get Answer"):
|
| 25 |
+
if not context.strip() or not question.strip():
|
| 26 |
+
st.warning("Please enter both context and question.")
|
| 27 |
+
else:
|
| 28 |
+
result = qa(question=question, context=context)
|
| 29 |
+
st.subheader("π Answer")
|
| 30 |
+
st.write(f"**Answer:** {result['answer']}")
|
| 31 |
+
st.write(f"**Confidence Score:** {round(result['score'], 3)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
+
main()
|