Spaces:
Running
Running
add openrouter api
Browse files
app.py
CHANGED
@@ -2,12 +2,15 @@ import gradio as gr
|
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
from openai import OpenAI
|
5 |
-
import anthropic
|
6 |
|
7 |
client = OpenAI(
|
8 |
api_key=os.getenv("OPENAI_API_KEY"),
|
9 |
)
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
ydl_opts = {
|
13 |
'outtmpl': 'demo.m4a',
|
@@ -41,16 +44,13 @@ def download_audio(url):
|
|
41 |
def summarize_text():
|
42 |
prompt = f"Please summarize the following article in 5 sentences or less use the language of the audio: [{text}]"
|
43 |
print(prompt)
|
44 |
-
|
45 |
-
model="
|
46 |
-
max_tokens=1000,
|
47 |
-
temperature=0.0,
|
48 |
-
# system="Respond only in mandarin",
|
49 |
messages=[
|
50 |
{"role": "user", "content": prompt}
|
51 |
]
|
52 |
)
|
53 |
-
return
|
54 |
|
55 |
with gr.Blocks() as demo:
|
56 |
with gr.Column():
|
|
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
from openai import OpenAI
|
|
|
5 |
|
6 |
client = OpenAI(
|
7 |
api_key=os.getenv("OPENAI_API_KEY"),
|
8 |
)
|
9 |
+
|
10 |
+
opnerouter_client = OpenAI(
|
11 |
+
base_url="https://openrouter.ai/api/v1",
|
12 |
+
api_key=os.getenv("OPENROUTER_API_KEY"),
|
13 |
+
)
|
14 |
|
15 |
ydl_opts = {
|
16 |
'outtmpl': 'demo.m4a',
|
|
|
44 |
def summarize_text():
|
45 |
prompt = f"Please summarize the following article in 5 sentences or less use the language of the audio: [{text}]"
|
46 |
print(prompt)
|
47 |
+
completion = opnerouter_client.chat.completions.create(
|
48 |
+
model="google/gemini-pro",
|
|
|
|
|
|
|
49 |
messages=[
|
50 |
{"role": "user", "content": prompt}
|
51 |
]
|
52 |
)
|
53 |
+
return completion.choices[0].message.content
|
54 |
|
55 |
with gr.Blocks() as demo:
|
56 |
with gr.Column():
|
demo.py
CHANGED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
from os import getenv
|
3 |
+
|
4 |
+
# gets API Key from environment variable OPENAI_API_KEY
|
5 |
+
client = OpenAI(
|
6 |
+
base_url="https://openrouter.ai/api/v1",
|
7 |
+
api_key=getenv(""),
|
8 |
+
)
|
9 |
+
|
10 |
+
completion = client.chat.completions.create(
|
11 |
+
model="google/gemini-pro",
|
12 |
+
messages=[
|
13 |
+
{
|
14 |
+
"role": "user",
|
15 |
+
"content": "how to learn rust programming language",
|
16 |
+
},
|
17 |
+
],
|
18 |
+
)
|
19 |
+
print(completion.choices[0].message.content)
|