danylokk commited on
Commit
8916035
·
verified ·
1 Parent(s): 0f89ec9

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +34 -0
main.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from openai import OpenAI
3
+
4
+ def summarize_text(api_key, text):
5
+ if not api_key:
6
+ return "Please provide an API key."
7
+ if not text:
8
+ return "Please provide text to summarize."
9
+ try:
10
+ client = OpenAI(api_key=api_key, base_url="https://api.groq.com/openai/v1")
11
+ response = client.chat.completions.create(
12
+ model="openai/gpt-oss-20b",
13
+ messages=[
14
+ {"role": "system", "content": "You are a helpful assistant that summarizes text clearly and concisely."},
15
+ {"role": "user", "content": f"Summarize the following text:\n\n{text}"}
16
+ ],
17
+ )
18
+ return response.choices[0].message.content
19
+ except Exception as e:
20
+ return f"An error occurred: {str(e)}"
21
+
22
+
23
+ api_key=gr.Textbox(label="API Key", type="password")
24
+ text=gr.Textbox(label="Text to summarize")
25
+ output_text=gr.Textbox(label="Summary")
26
+ demo = gr.Interface(
27
+ title="Summarize a text!",
28
+ description="Simple app that accepts a text and returns a summary. API key from Groq is required.",
29
+ fn=summarize_text,
30
+ inputs=[api_key,text],
31
+ outputs=[output_text]
32
+ )
33
+
34
+ demo.launch()