pls work
Browse files
app.py
CHANGED
@@ -1,20 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
from PyPDF2 import PdfReader
|
4 |
|
5 |
-
# Models
|
6 |
models = {
|
7 |
-
"Text Generator (
|
8 |
-
"
|
9 |
-
"tokenizer": AutoTokenizer.from_pretrained("bigscience/bloom-560m"),
|
10 |
},
|
11 |
"PDF Summarizer (T5)": {
|
12 |
-
"
|
13 |
-
"tokenizer": AutoTokenizer.from_pretrained("aaliyaan/t5-small-finetuned-career"),
|
14 |
},
|
15 |
"Broken Answer (T0pp)": {
|
16 |
-
"
|
17 |
-
"tokenizer": AutoTokenizer.from_pretrained("bigscience/T0pp"),
|
18 |
},
|
19 |
}
|
20 |
|
@@ -28,24 +25,25 @@ def chat_with_model(model_choice, user_message, chat_history, file=None):
|
|
28 |
return chat_history
|
29 |
|
30 |
model_info = models[model_choice]
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
|
50 |
# Update Chat History
|
51 |
chat_history.append((user_message, response))
|
@@ -79,7 +77,7 @@ def create_chat_interface():
|
|
79 |
with gr.Row():
|
80 |
model_choice = gr.Dropdown(
|
81 |
choices=list(models.keys()),
|
82 |
-
value="Text Generator (
|
83 |
label="Select Model"
|
84 |
)
|
85 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
from PyPDF2 import PdfReader
|
4 |
|
5 |
+
# Models Setup
|
6 |
models = {
|
7 |
+
"Text Generator (Zephyr)": {
|
8 |
+
"client": InferenceClient(model="HuggingFaceH4/zephyr-7b-beta"),
|
|
|
9 |
},
|
10 |
"PDF Summarizer (T5)": {
|
11 |
+
"client": InferenceClient(model="aaliyaan/t5-small-finetuned-career"),
|
|
|
12 |
},
|
13 |
"Broken Answer (T0pp)": {
|
14 |
+
"client": InferenceClient(model="bigscience/T0pp"),
|
|
|
15 |
},
|
16 |
}
|
17 |
|
|
|
25 |
return chat_history
|
26 |
|
27 |
model_info = models[model_choice]
|
28 |
+
client = model_info["client"]
|
29 |
+
|
30 |
+
# Prepare messages for the InferenceClient
|
31 |
+
messages = [
|
32 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
33 |
+
{"role": "user", "content": user_message}
|
34 |
+
]
|
35 |
+
|
36 |
+
# Generate Response
|
37 |
+
response = ""
|
38 |
+
for message in client.chat_completion(
|
39 |
+
messages,
|
40 |
+
max_tokens=150,
|
41 |
+
stream=True,
|
42 |
+
temperature=0.7,
|
43 |
+
top_p=0.95
|
44 |
+
):
|
45 |
+
token = message.choices[0].delta.content
|
46 |
+
response += token
|
47 |
|
48 |
# Update Chat History
|
49 |
chat_history.append((user_message, response))
|
|
|
77 |
with gr.Row():
|
78 |
model_choice = gr.Dropdown(
|
79 |
choices=list(models.keys()),
|
80 |
+
value="Text Generator (Zephyr)",
|
81 |
label="Select Model"
|
82 |
)
|
83 |
|