chatgpt version
Browse files
app.py
CHANGED
|
@@ -1,26 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
| 12 |
-
output = model.generate(input_ids, max_length=1000, do_sample=True, top_p=0.92, top_k=0, num_return_sequences=1)
|
| 13 |
-
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 14 |
-
return response
|
| 15 |
|
| 16 |
# Create the Gradio interface
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
chatbot_input = gr.Textbox(placeholder="Type your message here...")
|
| 22 |
-
chatbot_output = gr.Textbox(label="Chatbot Response")
|
| 23 |
-
chat_btn = gr.Button("Send")
|
| 24 |
-
chat_btn.click(chatbot, inputs=chatbot_input, outputs=chatbot_output)
|
| 25 |
-
|
| 26 |
-
chat_interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# Mock LLM function for demonstration. Replace this with your actual LLM call.
|
| 4 |
+
def ask_llm(question):
|
| 5 |
+
# Here you would normally interact with an LLM. For demonstration, we'll just echo the question.
|
| 6 |
+
return f"LLM Response: {question}"
|
| 7 |
|
| 8 |
+
def chat_with_llm(user_input):
|
| 9 |
+
return ask_llm(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Create the Gradio interface
|
| 12 |
+
iface = gr.Interface(fn=chat_with_llm,
|
| 13 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Ask me anything!"),
|
| 14 |
+
outputs="text",
|
| 15 |
+
title="Chat with LLM",
|
| 16 |
+
description="Type your question below and get responses from an LLM.")
|
| 17 |
|
| 18 |
+
# Launch the app
|
| 19 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|