Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,7 @@ client = AsyncOpenAI(
|
|
10 |
)
|
11 |
|
12 |
assistantID = os.getenv("OPENAI_ASSISTANT_ID")
|
13 |
-
|
14 |
-
password = os.getenv("YOUR_PASSWORD")
|
15 |
|
16 |
mytitle = "<h1 align=center>RTL AI News Reader : Wat war lass am Land 🇱🇺 an op der Welt 🌎 ?</h1>"
|
17 |
|
@@ -29,22 +28,14 @@ myarticle ="""
|
|
29 |
<h3>Hannergrënn :</h3>
|
30 |
<p>Dës HuggingFace Space Demo gouf vum <a href="https://github.com/mbarnig">Marco Barnig</a> realiséiert.
|
31 |
Als kënstlech Intelligenz gëtt, mëttels API, den <a href="https://platform.openai.com/docs/models">OpenAI Modell</a>
|
32 |
-
gpt-4o-mini-2024-07-18 benotzt
|
33 |
-
Tokens ka ginn a bis zu 200.000 Tokens pro Minutt (TPM) ka beaarbechten.
|
34 |
-
De ganze lëtzebuergesche Contenu vun RTL.lu vum Ufank (2000, 2012, ???) bis September 2024 gouf a 50 JSON-Dateien opgespléckt an op
|
35 |
-
e Vector Store vum OpenAI File-Search Assistent "RTL News Reader" eropgelueden.
|
36 |
-
All Datei huet manner wéi 5 Milliounen Token, wat eng iewescht Grenz fir den AI Modell ass.
|
37 |
-
Et ass méiglech bis zu 10.000 Dateien op en OpenAI Assistent opzelueden.
|
38 |
-
D'Äntwerte vun de Beispiller sinn am Cache gespäichert a ginn duerfir ouni Delai ugewise.</p>
|
39 |
"""
|
40 |
|
41 |
-
myinput =
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
"Wat fir eng Katastroph war 2022 zu Lëtzebuerg ?",
|
47 |
-
"Koumen an de leschte Jore gréisser Kriminalfäll viru Geriicht ?"
|
48 |
]
|
49 |
|
50 |
class EventHandler(AsyncAssistantEventHandler):
|
@@ -116,21 +107,34 @@ async def generate_response(user_input):
|
|
116 |
yield event_handler.response_text
|
117 |
|
118 |
# Gradio interface function (generator)
|
119 |
-
async def gradio_chat_interface(user_input):
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
# Set up Gradio interface with streaming
|
136 |
interface = gr.Interface(
|
@@ -141,9 +145,8 @@ interface = gr.Interface(
|
|
141 |
description=mydescription,
|
142 |
article=myarticle,
|
143 |
live=False,
|
144 |
-
allow_flagging="never"
|
145 |
-
examples=myexamples
|
146 |
)
|
147 |
|
148 |
# Launch the Gradio app
|
149 |
-
interface.launch(
|
|
|
10 |
)
|
11 |
|
12 |
assistantID = os.getenv("OPENAI_ASSISTANT_ID")
|
13 |
+
mypassword = os.getenv("RTL_PASSWORD")
|
|
|
14 |
|
15 |
mytitle = "<h1 align=center>RTL AI News Reader : Wat war lass am Land 🇱🇺 an op der Welt 🌎 ?</h1>"
|
16 |
|
|
|
28 |
<h3>Hannergrënn :</h3>
|
29 |
<p>Dës HuggingFace Space Demo gouf vum <a href="https://github.com/mbarnig">Marco Barnig</a> realiséiert.
|
30 |
Als kënstlech Intelligenz gëtt, mëttels API, den <a href="https://platform.openai.com/docs/models">OpenAI Modell</a>
|
31 |
+
gpt-4o-mini-2024-07-18 benotzt.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
"""
|
33 |
|
34 |
+
myinput = [
|
35 |
+
gr.Radio(["Sich", "Bispiller"]. label = "D'Beispiller fonktionnéieren ouni Passwuert.", value = "Beispiller",)
|
36 |
+
gr.Textbox(lines=1, label="Gitt dat richtegt RTL-Passwuert an !", scale=1),
|
37 |
+
gr.Textbox(lines=3, label="Wat wëllt Der wëssen ?", scale=7),
|
38 |
+
gr.Radio(["Wat war lass am Juni 2023 ?", "Wat ass gewosst iwwert de SREL ?", "Wat fir eng Katastroph war 2022 zu Lëtzebuerg ?", "Koumen an de leschte Jore gréisser Kriminalfäll viru Geriicht ?"], label="Beispiller")
|
|
|
|
|
39 |
]
|
40 |
|
41 |
class EventHandler(AsyncAssistantEventHandler):
|
|
|
107 |
yield event_handler.response_text
|
108 |
|
109 |
# Gradio interface function (generator)
|
110 |
+
async def gradio_chat_interface(mode, password, user_input, example):
|
111 |
+
if mode == "Exemples":
|
112 |
+
filename = example[-6:-2] + ".md"
|
113 |
+
file = open("examples/" + filename, "r")
|
114 |
+
output = file.read()
|
115 |
+
yield output
|
116 |
+
else:
|
117 |
+
# check the password
|
118 |
+
if password == "":
|
119 |
+
yield "Ouni RTL-Passwuert fonctionnéirt d'Sich net !"
|
120 |
+
elif password != mypassword:
|
121 |
+
yield "Gitt dat richtegt RTL-Passwuert an !"
|
122 |
+
else:
|
123 |
+
|
124 |
+
# Create a new event loop if none exists (or if we are in a new thread)
|
125 |
+
try:
|
126 |
+
loop = asyncio.get_running_loop()
|
127 |
+
except RuntimeError:
|
128 |
+
loop = asyncio.new_event_loop()
|
129 |
+
asyncio.set_event_loop(loop)
|
130 |
+
|
131 |
+
# Initialize the thread if not already done
|
132 |
+
if session_data["thread_id"] is None:
|
133 |
+
await initialize_thread()
|
134 |
+
|
135 |
+
# Generate and yield responses
|
136 |
+
async for response in generate_response(user_input):
|
137 |
+
yield response
|
138 |
|
139 |
# Set up Gradio interface with streaming
|
140 |
interface = gr.Interface(
|
|
|
145 |
description=mydescription,
|
146 |
article=myarticle,
|
147 |
live=False,
|
148 |
+
allow_flagging="never"
|
|
|
149 |
)
|
150 |
|
151 |
# Launch the Gradio app
|
152 |
+
interface.launch()
|