Spaces:
Sleeping
Sleeping
camparchimedes
commited on
Commit
•
2b1ef13
1
Parent(s):
8272aaf
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
import pandas as pd
|
4 |
-
import json
|
5 |
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
7 |
|
|
|
8 |
def respond(
|
9 |
message,
|
10 |
history: list[tuple[str, str]],
|
@@ -12,7 +11,6 @@ def respond(
|
|
12 |
max_tokens,
|
13 |
temperature,
|
14 |
top_p,
|
15 |
-
uploaded_file,
|
16 |
):
|
17 |
messages = [{"role": "system", "content": system_message}]
|
18 |
|
@@ -32,50 +30,19 @@ def respond(
|
|
32 |
stream=True,
|
33 |
temperature=temperature,
|
34 |
top_p=top_p,
|
35 |
-
uploaded_file = uploaded_file,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
# Process
|
43 |
-
if uploaded_file is not None:
|
44 |
-
print(f"Uploaded file: {uploaded_file.name}")
|
45 |
-
|
46 |
-
# Process CSV
|
47 |
-
if uploaded_file.name.endswith(".csv"):
|
48 |
-
try:
|
49 |
-
df = pd.read_csv(uploaded_file.name)
|
50 |
-
print(f"CSV file loaded with {len(df)} rows and {len(df.columns)} columns.")
|
51 |
-
json_data = df.to_json(orient="records")
|
52 |
-
with open(f"{uploaded_file.name.split('.')[0]}.json", "w") as json_file:
|
53 |
-
json_file.write(json_data)
|
54 |
-
print(f"JSON file created: {uploaded_file.name.split('.')[0]}.json")
|
55 |
-
except Exception as e:
|
56 |
-
print(f"Error loading CSV file: {e}")
|
57 |
-
|
58 |
-
# Process text
|
59 |
-
elif uploaded_file.name.endswith(".txt"):
|
60 |
-
try:
|
61 |
-
with open(uploaded_file.name, "r") as f:
|
62 |
-
text = f.read()
|
63 |
-
print(f"Text file loaded with {len(text)} characters.")
|
64 |
-
json_data = json.dumps({"text": text})
|
65 |
-
with open(f"{uploaded_file.name.split('.')[0]}.json", "w") as json_file:
|
66 |
-
json_file.write(json_data)
|
67 |
-
print(f"JSON file created: {uploaded_file.name.split('.')[0]}.json")
|
68 |
-
except Exception as e:
|
69 |
-
print(f"Error loading text file: {e}")
|
70 |
-
|
71 |
-
# Add more ? shit doesn't work
|
72 |
"""
|
73 |
For information on how to customize the ChatInterface: https://www.gradio.app/docs/chatinterface
|
74 |
"""
|
75 |
demo = gr.ChatInterface(
|
76 |
-
respond,
|
77 |
-
title="Nixie Steamcore, a hotbot!",
|
78 |
additional_inputs=[
|
|
|
79 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
80 |
gr.Slider(minimum=0.1, maximum=4.0, value=1.2, step=0.1, label="Temperature"),
|
81 |
gr.Slider(
|
@@ -85,10 +52,9 @@ demo = gr.ChatInterface(
|
|
85 |
step=0.05,
|
86 |
label="Top-p (nucleus sampling)",
|
87 |
),
|
88 |
-
gr.File(label="Upload a document"),
|
89 |
],
|
90 |
)
|
91 |
|
92 |
-
if __name__ == "__main__":
|
93 |
-
demo.launch(share=True, debug=True)
|
94 |
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
+
|
7 |
def respond(
|
8 |
message,
|
9 |
history: list[tuple[str, str]],
|
|
|
11 |
max_tokens,
|
12 |
temperature,
|
13 |
top_p,
|
|
|
14 |
):
|
15 |
messages = [{"role": "system", "content": system_message}]
|
16 |
|
|
|
30 |
stream=True,
|
31 |
temperature=temperature,
|
32 |
top_p=top_p,
|
|
|
33 |
):
|
34 |
token = message.choices[0].delta.content
|
35 |
|
36 |
response += token
|
37 |
yield response
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
"""
|
40 |
For information on how to customize the ChatInterface: https://www.gradio.app/docs/chatinterface
|
41 |
"""
|
42 |
demo = gr.ChatInterface(
|
43 |
+
respond, title="Nixie Steamcore, a hotbot!"
|
|
|
44 |
additional_inputs=[
|
45 |
+
#gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
46 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
47 |
gr.Slider(minimum=0.1, maximum=4.0, value=1.2, step=0.1, label="Temperature"),
|
48 |
gr.Slider(
|
|
|
52 |
step=0.05,
|
53 |
label="Top-p (nucleus sampling)",
|
54 |
),
|
|
|
55 |
],
|
56 |
)
|
57 |
|
|
|
|
|
58 |
|
59 |
+
if __name__ == "__main__":
|
60 |
+
demo.launch()
|