lachie0232 commited on
Commit
c750edf
·
verified ·
1 Parent(s): e07e9e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -13
app.py CHANGED
@@ -1,19 +1,70 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load your model
5
- model_name = "lachie0232/Jammy-finetuned" # Replace with your model's name
6
- qa_pipeline = pipeline("question-answering", model=model_name)
 
7
 
8
- # Define the function to handle user input
9
- def answer_question(question):
10
- context = "Insert your context or provide default knowledge."
11
- result = qa_pipeline(question=question, context=context)
12
- return result['answer']
13
 
14
- # Create a Gradio interface
15
- interface = gr.Interface(fn=answer_question, inputs="text", outputs="text")
16
 
17
- # Launch the interface
18
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ """
5
+ For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
+ """
7
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
 
 
 
9
 
 
 
10
 
11
+
12
+
13
+
14
+
15
+ def respond(
16
+ message,
17
+ history: list[tuple[str, str]],
18
+ system_message,
19
+ max_tokens,
20
+ temperature,
21
+ top_p,
22
+ ):
23
+ messages = [{"role": "system", "content": system_message}]
24
+
25
+ for val in history:
26
+ if val[0]:
27
+ messages.append({"role": "user", "content": val[0]})
28
+ if val[1]:
29
+ messages.append({"role": "assistant", "content": val[1]})
30
+
31
+ messages.append({"role": "user", "content": message})
32
+
33
+ response = ""
34
+
35
+ for message in client.chat_completion(
36
+ messages,
37
+ max_tokens=max_tokens,
38
+ stream=True,
39
+ temperature=temperature,
40
+ top_p=top_p,
41
+ ):
42
+ token = message.choices[0].delta.content
43
+
44
+ response += token
45
+ yield response
46
+
47
+
48
+ """
49
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
50
+ """
51
+ demo = gr.ChatInterface(
52
+ respond,
53
+ additional_inputs=[
54
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
55
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
56
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
57
+ gr.Slider(
58
+ minimum=0.1,
59
+ maximum=1.0,
60
+ value=0.95,
61
+ step=0.05,
62
+ label="Top-p (nucleus sampling)",
63
+ ),
64
+ ],
65
+ )
66
+
67
+
68
+ if __name__ == "__main__":
69
+ demo.launch()
70