WingNeville commited on
Commit
5f3ed4e
·
verified ·
1 Parent(s): 4adf2aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -28
app.py CHANGED
@@ -1,33 +1,36 @@
1
- import os
2
- from huggingface_hub import InferenceClient
3
- import gradio as gr
4
 
5
- # Function to test API connection
6
- def test_api_connection(query: str, api_key: str) -> str:
7
- """Tests the Hugging Face Inference API connection with the provided API key."""
8
- try:
9
- # Using a different model for testing
10
- client = InferenceClient(model="distilbert-base-uncased", token=api_key)
11
- response = client.text_classification(query)
12
- return f"API connection successful! Response: {response}"
13
- except Exception as e:
14
- return f"Error: {str(e)}"
15
 
16
- # Gradio interface function
17
- def run_agent(query):
18
- api_key = os.getenv("WingTokenAll")
19
- if not api_key:
20
- return "Error: wingTokenRead not found in environment variables."
21
- return test_api_connection(query, api_key)
22
 
23
- # Create and launch Gradio interface
24
- interface = gr.Interface(
25
- fn=run_agent,
26
- inputs=gr.Textbox(label="Enter a test query", placeholder="e.g., This is a test sentence"),
27
- outputs=gr.Textbox(label="API Test Response"),
28
- title="Hugging Face API Test",
29
- description="Enter a test query to verify the Hugging Face API connection."
30
- )
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  if __name__ == "__main__":
33
- interface.launch(server_port=7860, share=True, quiet=True)
 
1
+ from transformers import pipeline
 
 
2
 
3
+ # Predefined context
4
+ context = """
5
+ The Scrum framework consists of Scrum Teams and their roles, events, and artifacts.
6
+ Scrum Teams are self-managing and cross-functional. The main roles include the Scrum Master,
7
+ Product Owner, and Development Team. The Daily Stand-up is a short meeting for the Scrum Team
8
+ to synchronize activities and create a plan for the next 24 hours.
9
+ """
 
 
 
10
 
11
+ # Load the question-answering model
12
+ question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
 
 
 
 
13
 
14
+
15
+ def answer_question(question):
16
+ """Answer the question based on the predefined context."""
17
+ result = question_answerer(question=question, context=context)
18
+ return result['answer']
19
+
20
+ def main():
21
+ print("Welcome to the Simple Q&A Agent!")
22
+ print("Type 'exit' to quit.\n")
23
+
24
+ while True:
25
+ user_input = input("Ask a question: ")
26
+
27
+ if user_input.lower() == 'exit':
28
+ print("Goodbye!")
29
+ break
30
+
31
+
32
+ answer = answer_question(user_input)
33
+ print(f"Answer: {answer}\n")
34
 
35
  if __name__ == "__main__":
36
+ main()