Spaces:
Sleeping
Sleeping
File size: 2,776 Bytes
feb85b6 fe6b3c1 feb85b6 fe6b3c1 f48ea54 fe6b3c1 f48ea54 feb85b6 f48ea54 feb85b6 f48ea54 feb85b6 f48ea54 fe6b3c1 f48ea54 fe6b3c1 feb85b6 923b0f3 f48ea54 feb85b6 923b0f3 feb85b6 f48ea54 feb85b6 f48ea54 feb85b6 f48ea54 feb85b6 f48ea54 fe6b3c1 f48ea54 a80221c f48ea54 feb85b6 f48ea54 feb85b6 f48ea54 feb85b6 f48ea54 a80221c a53fa7a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import requests
import gradio as gr
# Configuration (Update this with your ngrok URL)
API_URL = "https://5b9f-154-161-168-18.ngrok-free.app/v1/chat/completions"
HEADERS = {"Content-Type": "application/json"}
# Store the last prompt
last_prompt = ""
def generate(prompt):
"""Generation function with prompt storage"""
global last_prompt
last_prompt = prompt
try:
response = requests.post(
API_URL,
headers=HEADERS,
json={
"model": "TinyLlama-1.1B-Chat-v1.0",
"messages": [{"role": "user", "content": prompt}],
"max_tokens": 256,
"temperature": 0.7
},
timeout=30
)
return response.json()['choices'][0]['message']['content']
except Exception as e:
return f"Error: {str(e)}"
def regenerate():
"""Regenerate response using last prompt"""
if last_prompt:
return generate(last_prompt)
return "No previous prompt to regenerate"
# Gradio UI
with gr.Blocks(title="Karlson Achegeba GPT", theme=gr.themes.Soft(primary_hue="blue")) as app:
with gr.Column(elem_classes=["center-container"]):
# Header
gr.Markdown("""<div style='text-align: center'>
<h1 style='color: #2563eb'>Karlson Achegeba GPT</h1>
<p>My very first trained model</p>
</div>""")
# Chat Interface
with gr.Group():
prompt = gr.Textbox(
placeholder="Type your message...",
lines=5,
label="Your Message",
elem_classes=["input-box"]
)
with gr.Row():
submit = gr.Button("Generate", variant="primary")
regenerate_btn = gr.Button("Regenerate", variant="secondary")
clear_btn = gr.Button("Clear All", variant="secondary")
output = gr.Textbox(
label="AI Response",
interactive=False,
lines=8,
elem_classes=["output-box"]
)
# Event Handlers
submit.click(fn=generate, inputs=prompt, outputs=output)
regenerate_btn.click(fn=regenerate, outputs=output)
clear_btn.click(fn=lambda: ("", ""), outputs=[prompt, output])
# CSS Styling
app.css = """
.center-container { max-width: 800px; margin: auto; padding: 20px; }
.input-box, .output-box {
border-radius: 8px;
border: 1px solid #e2e8f0;
padding: 12px;
}
.action-button { min-width: 120px; }
.group {
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
"""
app.launch(share = "True") |