Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,23 @@
|
|
| 1 |
-
import
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
-
|
| 6 |
-
# Read Hugging Face Token from environment
|
| 7 |
-
hf_token = os.environ.get("HUGGINGFACE_TOKEN")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
tokenizer = AutoTokenizer.from_pretrained("cmlang/somali-flan-t5", use_auth_token=hf_token)
|
| 11 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("cmlang/somali-flan-t5", use_auth_token=hf_token)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
|
|
|
| 1 |
+
import openai
|
| 2 |
import gradio as gr
|
| 3 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def chat(user_input, history=[]):
|
| 8 |
+
messages = [{"role": "system", "content": "Ka jawaab su’aalaha af Soomaali"}]
|
| 9 |
+
for q, a in history:
|
| 10 |
+
messages.append({"role": "user", "content": q})
|
| 11 |
+
messages.append({"role": "assistant", "content": a})
|
| 12 |
+
messages.append({"role": "user", "content": user_input})
|
| 13 |
|
| 14 |
+
response = openai.ChatCompletion.create(
|
| 15 |
+
model="gpt-4o",
|
| 16 |
+
messages=messages,
|
| 17 |
+
temperature=0.7
|
| 18 |
+
)
|
| 19 |
+
reply = response.choices[0].message.content
|
| 20 |
+
history.append((user_input, reply))
|
| 21 |
+
return history, history
|
| 22 |
|
| 23 |
+
gr.ChatInterface(chat, title="Chatbot Af Soomaali").launch()
|