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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -65
app.py CHANGED
@@ -1,70 +1,18 @@
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
 
 
1
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ # Load your custom-trained model
4
+ model_name = "lachie0234/jammy-finetuned" # Replace with your model's name on Hugging Face
5
+ qa_pipeline = pipeline("question-answering", model=model_name)
 
 
 
 
 
 
6
 
7
+ # Define the function to handle user input
8
+ def answer_question(question):
9
+ context = "Legendary asnwer man."
10
+ result = qa_pipeline(question=question, context=context)
11
+ return result['answer']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ # Set up the Gradio interface
14
+ import gradio as gr
15
+ interface = gr.Interface(fn=answer_question, inputs="text", outputs="text")
16
+ interface.launch()
17
 
 
 
18