Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,42 +46,39 @@ import gradio as gr
|
|
| 46 |
from huggingface_hub import InferenceClient
|
| 47 |
import os
|
| 48 |
|
| 49 |
-
# Initialize Hugging Face Inference Client
|
| 50 |
hf_token = os.getenv("HF_TOKEN")
|
| 51 |
client = InferenceClient(api_key=hf_token)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
def chatbot(input_text, history=[]):
|
| 55 |
-
#messages = [{"role": "user", "content": input_text}]
|
| 56 |
messages = []
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
messages.append({"role": "
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
stream = client.chat.completions.create(
|
| 63 |
-
model="google/gemma-2-2b-it",
|
| 64 |
-
messages=messages,
|
| 65 |
-
#temperature=0.5,
|
| 66 |
-
#max_tokens=2048,
|
| 67 |
-
#top_p=0.7,
|
| 68 |
-
stream=True
|
| 69 |
)
|
| 70 |
|
| 71 |
-
# Concatenate streamed response
|
| 72 |
bot_response = "".join(chunk.choices[0].delta.content for chunk in stream)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
history.append((input_text, bot_response))
|
| 76 |
return bot_response, history
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 46 |
from huggingface_hub import InferenceClient
|
| 47 |
import os
|
| 48 |
|
|
|
|
| 49 |
hf_token = os.getenv("HF_TOKEN")
|
| 50 |
client = InferenceClient(api_key=hf_token)
|
| 51 |
|
| 52 |
+
def fn(prompt, history=[]):
|
|
|
|
|
|
|
| 53 |
messages = []
|
| 54 |
+
|
| 55 |
+
for user_prompt, bot_response in history:
|
| 56 |
+
messages.append({"role": "user", "content": user_prompt})
|
| 57 |
+
messages.append({"role": "bot", "content": bot_response})
|
| 58 |
+
|
| 59 |
+
messages.append({"role": "user", "content": prompt})
|
| 60 |
|
| 61 |
stream = client.chat.completions.create(
|
| 62 |
+
model = "google/gemma-2-2b-it",
|
| 63 |
+
messages = messages,
|
| 64 |
+
#temperature = 0.5,
|
| 65 |
+
#max_tokens = 2048,
|
| 66 |
+
#top_p = 0.7,
|
| 67 |
+
stream = True
|
| 68 |
)
|
| 69 |
|
|
|
|
| 70 |
bot_response = "".join(chunk.choices[0].delta.content for chunk in stream)
|
| 71 |
|
| 72 |
+
history.append((prompt, bot_response))
|
|
|
|
| 73 |
return bot_response, history
|
| 74 |
|
| 75 |
+
app = gr.Interface(
|
| 76 |
+
fn = fn,
|
| 77 |
+
inputs = [gr.Textbox(label = "Input")],
|
| 78 |
+
outputs = [gr.Textbox(label = "Output")],
|
| 79 |
+
title = "Google Gemma",
|
| 80 |
+
description = "Chatbot",
|
| 81 |
+
examples = [
|
| 82 |
+
["Hello, World."]
|
| 83 |
+
]
|
| 84 |
+
).launch()
|