Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,3 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import openai
|
| 3 |
|
| 4 |
-
|
| 5 |
-
base_url="http://localhost:11434/v1/",
|
| 6 |
-
api_key="ollama" # Required but unused by Ollama
|
| 7 |
-
)
|
| 8 |
-
|
| 9 |
-
def chat_with_code(message, history):
|
| 10 |
-
response = client.chat.completions.create(
|
| 11 |
-
model="llama3.2",
|
| 12 |
-
messages=[{"role": "user", "content": message}],
|
| 13 |
-
temperature=0.7
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
full_response = response.choices[0].message.content
|
| 17 |
-
code_block = None
|
| 18 |
-
|
| 19 |
-
# Extract code blocks from response
|
| 20 |
-
if "```python" in full_response:
|
| 21 |
-
code = full_response.split("```python")[1].split("```")[0].strip()
|
| 22 |
-
code_block = gr.Code(language="python", value=code)
|
| 23 |
-
elif "```javascript" in full_response:
|
| 24 |
-
code = full_response.split("```javascript")[1].split("```")[0].strip()
|
| 25 |
-
code_block = gr.Code(language="javascript", value=code)
|
| 26 |
-
|
| 27 |
-
return full_response, code_block
|
| 28 |
-
|
| 29 |
-
with gr.Blocks() as demo:
|
| 30 |
-
code = gr.Code(render=False)
|
| 31 |
-
gr.ChatInterface(
|
| 32 |
-
fn=chat_with_code,
|
| 33 |
-
additional_outputs=[code],
|
| 34 |
-
type="messages"
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
gr.load_chat("http://localhost:11434/v1/", model="mistral-small", token="ollama").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|