Spaces:
Running
Running
# import gradio as gr | |
# from groq import Groq | |
# client = Groq( | |
# api_key=("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"), | |
# ) | |
# def generate_response(input_text): | |
# chat_completion = client.chat.completions.create( | |
# messages=[ | |
# { | |
# "role": "user", | |
# "content": input_text, | |
# } | |
# ], | |
# model="llama3-8b-8192", | |
# ) | |
# return chat_completion.choices[0].message.content | |
# iface = gr.Interface( | |
# fn=generate_response, | |
# inputs=gr.Textbox(label="ورودی" , lines=2, placeholder="اینجا یه چی بپرس... "), | |
# outputs=gr.Textbox(label="جواب"), | |
# title="💬 Parviz GPT", | |
# description="زنده باد", | |
# theme="dark", | |
# allow_flagging="never" | |
# ) | |
# iface.launch() | |
import gradio as gr | |
from groq import Groq | |
import time | |
client = Groq(api_key="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") | |
def generate_response(message, chat_history): | |
chat_completion = client.chat.completions.create( | |
messages=[{"role": "user", "content": message}], | |
model="llama3-8b-8192", | |
) | |
bot_message = chat_completion.choices[0].message.content | |
for i in range(0, len(bot_message), 10): | |
yield chat_history + [(message, bot_message[:i + 10])] | |
time.sleep(0.1) | |
yield chat_history + [(message, bot_message)] | |
with gr.Blocks() as demo: | |
gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1><p style='text-align: center; color: #e0e0e0;'>زنده باد</p>") | |
chatbot = gr.Chatbot(label="جواب") | |
msg = gr.Textbox(label="ورودی", placeholder="اینجا یه چی بپرس... ", lines=1) | |
msg.submit(generate_response, [msg, chatbot], chatbot) | |
clear = gr.ClearButton([msg, chatbot]) | |
demo.launch() | |
# import gradio as gr | |
# import torch | |
# from transformers import AutoTokenizer, AutoModelForCausalLM | |
# tokenizer = AutoTokenizer.from_pretrained("universitytehran/PersianMind-v1.0", use_fast=True) | |
# model = AutoModelForCausalLM.from_pretrained( | |
# "universitytehran/PersianMind-v1.0", | |
# torch_dtype=torch.bfloat16 | |
# ).to("cpu") | |
# CONTEXT = ( | |
# "This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, " | |
# "an NLP expert, to help you with various tasks such as answering questions, " | |
# "providing recommendations, and assisting with decision-making. Ask it anything!" | |
# ) | |
# pretokenized_context = tokenizer(CONTEXT, return_tensors="pt").input_ids.to("cpu") | |
# def generate_response(message, chat_history): | |
# prompt = torch.cat( | |
# [pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")], | |
# dim=1 | |
# ) | |
# with torch.no_grad(): | |
# outputs = model.generate( | |
# prompt, | |
# max_new_tokens=32, | |
# temperature=0.6, | |
# top_k=20, | |
# top_p=0.8, | |
# do_sample=True | |
# ) | |
# result = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
# response = result.split("ParvizGPT:")[-1].strip() | |
# return chat_history + [(message, response)] | |
# with gr.Blocks() as demo: | |
# gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1>") | |
# chatbot = gr.Chatbot(label="Response") | |
# msg = gr.Textbox(label="Input", placeholder="Ask your question...", lines=1) | |
# msg.submit(generate_response, [msg, chatbot], chatbot) | |
# gr.ClearButton([msg, chatbot]) | |
# demo.launch() |