Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,50 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
)
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
):
|
37 |
-
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
-
)
|
61 |
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
import os
|
3 |
+
from google import genai
|
4 |
+
from google.genai import types
|
5 |
import gradio as gr
|
|
|
6 |
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def generate(prompt):
|
9 |
+
client = genai.Client(
|
10 |
+
api_key=os.environ.get("GEMINI_API_KEY"),
|
11 |
+
)
|
12 |
|
13 |
+
model = "gemini-2.0-flash"
|
14 |
+
contents = [
|
15 |
+
types.Content(
|
16 |
+
role="user",
|
17 |
+
parts=[
|
18 |
+
types.Part.from_text(text=prompt),
|
19 |
+
],
|
20 |
+
),
|
21 |
+
]
|
22 |
+
tools = [
|
23 |
+
types.Tool(google_search=types.GoogleSearch())
|
24 |
+
]
|
25 |
+
generate_content_config = types.GenerateContentConfig(
|
26 |
+
temperature=0.35,
|
27 |
+
top_p=0.95,
|
28 |
+
top_k=40,
|
29 |
+
max_output_tokens=8192,
|
30 |
+
tools=tools,
|
31 |
+
response_mime_type="text/plain",
|
32 |
+
)
|
33 |
|
34 |
response = ""
|
35 |
+
for chunk in client.models.generate_content_stream(
|
36 |
+
model=model,
|
37 |
+
contents=contents,
|
38 |
+
config=generate_content_config,
|
|
|
|
|
|
|
39 |
):
|
40 |
+
response += chunk.text
|
41 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
+
iface = gr.ChatInterface(
|
46 |
+
fn=generate,
|
47 |
+
title="Gemini Chatbot with Google Search",
|
48 |
+
description="A chatbot powered by Gemini 2.0 Flash and Google Search.",
|
49 |
+
)
|
50 |
+
iface.launch()
|