HusseinBashir commited on
Commit
6c8e950
·
verified ·
1 Parent(s): 788f6df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()